﻿using System;
using Microsoft.ApplicationServer.Caching;

namespace Dexter.Caching.AppFabric {
	public class AppFabricCacheFactory {
		readonly DataCacheFactoryConfiguration cacheConfiguration;
		readonly DataCache cacheRepository;

		/// <summary>
		/// 	Initializes a new instance of the <see cref = "T:System.Object" /> class.
		/// </summary>
		public AppFabricCacheFactory ( DataCache cacheRepository , DataCacheFactoryConfiguration cacheConfiguration ) {
			this.cacheRepository = cacheRepository;
			this.cacheConfiguration = cacheConfiguration;
		}

		/// <summary>
		/// 	Initializes a new instance of the <see cref = "T:System.Object" /> class.
		/// </summary>
		public AppFabricCacheFactory ( ) {
			cacheConfiguration = new DataCacheFactoryConfiguration ( ) {
				Servers = new DataCacheServerEndpoint[] {
					new DataCacheServerEndpoint ( Environment.MachineName , 22233 ) ,
				} ,
				SecurityProperties = new DataCacheSecurity ( DataCacheSecurityMode.None, DataCacheProtectionLevel.None )
			};

			cacheRepository = new DataCacheFactory ( cacheConfiguration ).GetDefaultCache ( );
		}

		/// <summary>
		/// Gets the cache repository.
		/// </summary>
		/// <value>The cache repository.</value>
		public virtual DataCache CacheRepository {
			get { return cacheRepository; }
		}

		/// <summary>
		/// Gets the cache configuration.
		/// </summary>
		/// <value>The cache configuration.</value>
		public virtual DataCacheFactoryConfiguration CacheConfiguration {
			get { return cacheConfiguration; }
		}
	}
}